package com.xhwl.logistics.service.business;

import com.xhwl.logistics.bo.VehiclePassageSecondBO;
import com.xhwl.logistics.converter.mapstruct.VehiclePassageConverter;
import com.xhwl.logistics.dao.mapper.IVehicleParkingLotInfoMapper;
import com.xhwl.logistics.po.VehicleParkingLotInfoPO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

//@Service
public class VehiclePassageBusinessService {

    @Autowired
    private IVehicleParkingLotInfoMapper vehicleParkingLotInfoMapper;

    @Autowired
    private VehiclePassageConverter vehiclePassageConverter;

    public List<VehiclePassageSecondBO> queryPassage(Integer projectId) {
        Optional<VehicleParkingLotInfoPO> optionalVehicleParkingLotInfoPO = vehicleParkingLotInfoMapper.queryParkingLotInfoByProjectId(projectId);

        return optionalVehicleParkingLotInfoPO.map(vehicleParkingLotInfoPO -> vehicleParkingLotInfoPO.getVehicleParkingLotPOList().stream()
                .flatMap(vehicleParkingLotPO -> vehicleParkingLotPO.getVehicleAreaPOList().stream())
                .flatMap(vehicleAreaPO -> vehicleAreaPO.getVehiclePassageSecondPOList().stream())
                .map(vehiclePassageSecondPO -> vehiclePassageConverter.vehiclePassageSecondPO2VehiclePassageSecondBO(vehiclePassageSecondPO))
                .collect(Collectors.toList())).orElse(new ArrayList<>());
    }

}
